import { createStore } from 'vuex'
import createS from 'vuex-persistedstate'
export default createStore({
  state: {
    list: []
  },
  getters: {
    nums(state) {
      let num1 = JSON.parse(JSON.stringify(0))
      let num2 = JSON.parse(JSON.stringify(0))
      let num3 = JSON.parse(JSON.stringify(0))
      let num4 = JSON.parse(JSON.stringify(0))

      state.list.forEach(item => {
        if (item.resource == "昌平") {
          num1++;
        } else if (item.resource == "西安") {
          num2++;
        } else if (item.resource == "海淀") {
          num3++;
        } else {
          num4++;
        }

      })
      return [num1, num2, num3, num4]
    }

  },
  mutations: {
    add(state, i) {
      state.list.unshift(JSON.parse(JSON.stringify(i)))
    },
    del(state, i) {
      state.list.splice(i, 1)
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [createS()]
})
